package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo10 {
    public static void main(String[] args) {
        try ( Connection connection = DBUtil.getConnection()){
          connection.setAutoCommit(false);
          String sql = "DELETE FROM user WHERE id=?";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setInt(1,2);
            int num = preparedStatement.executeUpdate();
            System.out.println(num>0?"删除成功":"删除失败");

            //connection.rollback();
            connection.commit();

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
